#ifndef ITERATOR_H_
#define ITERATOR_H_

#include "collection.h"

template <class Item>
class Iterator
{
public:
	virtual ~Iterator() {}

protected:
	Iterator() {}

public:
	virtual void first() = 0;
	virtual void next() = 0;
	virtual bool isDone() const = 0;
	virtual Item* curItem() = 0;
};

template <class Item>
class ListIterator : public List<Item>
{
public:
	ListIterator(const List<Item>*);
	virtual ~ListIterator();

public:
	virtual void first();
	virtual void next();
	virtual bool isDone() const;
	virtual const Item* curItem();

private:
	int m_index;
	const List<Item>* m_list;
};

template <class Item>
ListIterator<Item>::ListIterator(const List<Item>* pList)
: m_list(pList) // const class member should be init here.
{
	m_index = -1;
}

template <class Item>
ListIterator<Item>::~ListIterator()
{
}

template <class Item>
void ListIterator<Item>::first()
{
	m_index = 0;
}

template <class Item>
void ListIterator<Item>::next()
{
	++m_index;
}

template <class Item>
bool ListIterator<Item>::isDone() const
{
	return (m_index >= m_list->count());
}

template <class Item>
const Item* ListIterator<Item>::curItem()
{
	if (isDone())
	{
		throw -1;
	} 
	else
	{
		return m_list->get(m_index);
	}
}

#endif // ITERATOR_H_
